#获取艾瑞网最新报告
import re,json
import requests
from bs4 import BeautifulSoup

# 发起HTTP请求获取网页内容
url = 'https://www.zhihu.com/billboard'

response = requests.get(url)
response.encoding = 'UTF-8' # 或者其他正确的编码方式

# 解析网页内容
soup = BeautifulSoup(response.text, 'html.parser')

# print(soup)

# 提取新闻内容
news_content = soup.find('div', class_='Card').get_text()


# 打印新闻内容
# print(news_content)

# 使用正则表达式按照"热度"进行分割
result = re.split(r'热度', news_content)
result_str = "【知乎热点】\n"
# 打印分割结果,并且只打印前面10行
for item in result[:10]:
    result_str += "\n" + item.strip() + "\n"
    # print(item.strip())

print(result_str)

#发送vx消息
url = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=d230f478-24eb-4780-a45d-0e8fe951bded'
headers = {'Content-Type': 'application/json'}
#文本
#带超链接
#article ="<a href=\"http://baidu.com\">邮件中心视频实况</a>"


data = {
    "msgtype": "text",
    "text": {
        "content": result_str
    },
    "safe": 0,
    "enable_id_trans": 0,
    "enable_duplicate_check": 0,
    "duplicate_check_interval": 1800
}
response = requests.post(url, headers=headers, data=json.dumps(data))